package com.niuzi.servlet;

import com.niuzi.entity.Student;
import com.niuzi.util.DataUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/addstudent")
public class AddStudentServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        String sex = req.getParameter("sex");
        System.out.println("姓名："+name+"年龄："+age+"性别："+sex);


        Student student = new Student();
        student.setName(name);
        student.setAge(age);
        student.setSex(sex);

        //保存数据库
        DataUtil.addStudent(student);
        resp.sendRedirect("addstudent.jsp?status=1");

    }
}
